package com.eos.control.action.emp;

import java.util.Date;

import com.eos.business.service.SysUserBusinessService;
import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysRole;


public class SaveRoleAction extends AbstractBaseAction {
	private static final long serialVersionUID = 181976464336631651L;
	private String roleName;
	private String roleDesc;
	
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	
	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}

	@Override
	public String execute()  {
		try{
			Date date = new Date(System.currentTimeMillis());
			String strTime = ObjectUtils.formatDate(date, null);
			SysRole role = new SysRole();
			role.setDealFlag("0");
			role.setStatus("0");
			role.setInsertTime(strTime);
			role.setModifyTime(strTime);
			role.setRoleDesc(roleDesc);
			role.setRoleName(roleName);
			SysUserBusinessService sbs = new SysUserBusinessService();
			String flag = sbs.saveRole(role);
			if("SUCCESS".equals(flag)){
				statusCode = "200";
				message = "新增角色成功!";
				DataCacheUtil.clearSysRoleMap();
			}else{
				statusCode = "300";
				message = "系统繁忙, 新增角色失败!";
			}
		}catch(Exception ex){
			ex.printStackTrace();
			statusCode = "300";
			message = "系统异常, 新增角色失败!";
		}
		return SUCCESS;
	}
}
